package engine.newUi
{
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.ResPath;
	import engine.logic.LogSendLogic;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.tip.TipsMainLogic;
	import engine.ui.AlertUI;
	
	import flash.display.DisplayObjectContainer;
	import flash.events.MouseEvent;
	
	import newx.com.config.StaticIni;
	import newx.com.control.window.NxWindowEvent;
	
	public class GetMagicCoinLogic
	{
		private static var _self:GetMagicCoinLogic
		
		private var _myDis:GetMagicCoinUI;
		private var _model:ModelLocator;
		public function GetMagicCoinLogic()
		{
			_model				=	ModelLocator.getInstance();
			_myDis				=	GetMagicCoinUI.getInstance();
		}
		public static function getInstance():GetMagicCoinLogic
		{
			if(_self == null)
			{
				_self = new GetMagicCoinLogic();
			}
			return _self;
		}
		
		public function init():void
		{
			//领取元宝
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_LOGIN_PRIZE_INFO),getGoldIsShow);
		}
		
		/**
		 * 开始监听
		 */		
		public function addListener():void
		{
			//请求领取元宝信息
			SystemSender.getInstance().CustomMsg( CustomToServerFlag. CLIENT_CUSTOMMSG_REQUEST_LOGIN_PRIZE_INFO );
		}
		/**
		 * 移除监听
		 */		
		public function removeListener():void
		{
			_model.removeEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_LOGIN_PRIZE_INFO),getGoldIsShow);
		}
		
		//领取元宝------------------------------------------------------------
		private function getGoldIsShow(e:CustomMsgEvent):void
		{
			var serviceArr:Array   = e.pList;
			
			var days:int	= serviceArr[0];		//登陆天数
			var award:int	= serviceArr[1];		//登陆奖励
			
			if(days > 0 && days <= 3){
				_myDis.infoText.htmlText = String(StaticIni.getSwfLangStrVar("UIString_1000314", [ award, days ]));
				_myDis.enterBtn.addEventListener(MouseEvent.CLICK, getGoldHandler);
			}
		}
		
		/**
		 * 请求领取元宝
		 */
		private function getGoldHandler(e:MouseEvent):void
		{
			SystemSender.getInstance().CustomMsg( CustomToServerFlag. CLIENT_CUSTOMMSG_REQUEST_GET_LOGIN_PRIZE );
			_myDis.hide();
			//打开VIP
			VipLogic.getInstence().ui.showOrHide();
		}
	}
}